﻿<%@ Page Language="C#" AutoEventWireup="false" CodeFile="recDevolutionProcessform.aspx.cs" Inherits="SIPO.Web.Forms.Transaction.recDevolutionProcessform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>

    <script src="<%= ResolveUrl("~/scripts/plupload/moxie.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/plupload.full.min.js") %>" type="text/javascript"></script>

    <script type="text/javascript">
        // 1. prepare the validation rules and messages.
        var rules = {
            ddlPengurusan: "required",
            txtNoSuratPengurusan: {
                    required: true,
                    maxlength: 10
                },
            txtTglSuratPengurusan: "required"

        };
        var messages = {
            ddlPengurusan: "Tahap Pengurusan wajib di pilih!",
            txtNoSuratPengurusan: "Nomor Surat Pengurusan wajib di isi dan panjang max karakter 18 !",
            txtTglSuratPengurusan: "Tgl. Surat Pengurusan wajib di isi!"

        };

        // 2. Initiate the validator
        var validator = new jQueryValidatorWrapper("form1", rules, messages);
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            //mengupload file
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight',
                browse_button: 'pickfiles',
                container: 'container',
                max_file_size: '5mb',
                url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=update',
                flash_swf_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
                silverlight_xap_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
                filters: [
            { title: "Pdf files", extensions: "pdf" },
            { title: "Excel files", extensions: "xls,xlsx" },
			{ title: "Text files", extensions: "txt" },
			{ title: "Image files", extensions: "jpeg,jpg,gif,png" },
            { title: "Word files", extensions: "doc,docx" },
			{ title: "PowerPoint files", extensions: "ppt,pptx" }
		],
                resize: { width: 320, height: 240, quality: 90 }
            });


            uploader.bind('Init', function (up, params) {

                var msg = 'Untuk dapat melakukan proses unggah / upload dokumen, browser anda harus mendukung salah satu teknologi, HTML 5 / Flash / Silverlight';

                if (params.runtime == 'html5') {
                    msg = '';
                } else if (params.runtime == 'flash') {
                    msg = '';
                } else if (params.runtime == 'silverlight') {
                    msg = ''
                }

                if (msg != '') {
                    alert(msg);
                }

            });

            uploader.init();

            uploader.bind('FilesAdded', function (up, files) {

                if (up.files.length > 1) {
                    alert('Hanya diperbolehkan satu file untuk di upload!');
                    return false;
                }

                $.each(files, function (i, file) {
                    $('#filelist').append(
                        '<div id="' + file.id + '">' +
                file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + '</div>');
                });

                up.refresh(); // Reposition Flash/Silverlight
            });

            uploader.bind('FileUploaded', function (up, file, info) {

                var err = JSON.parse(info.response);
                alert(err.Message);

            });

            uploader.bind('Error', function (up, err) {

                var errMsg = '';

                switch (err.code) {
                    case (-600):
                        errMsg = 'File tidak boleh lebih dari 5 Mb';
                        break;
                    case (-601):
                        errMsg = 'File harus berformat excel / word/ text / pdf / gambar';
                        break;
                    default:
                        errMsg = err.code + ' - ' + err.message;
                        break;
                }

                alert(errMsg);

                up.refresh(); // Reposition Flash/Silverlight

            });

            $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
            $("#btnSubmit").button({ icons: { primary: "ui-icon-disk"} });

            //disabled control
            $('#txtDebtorName').attr('disabled', 'disabled');
            $('#txtDebtorId').attr('disabled', 'disabled');
            $('#txtLetterNo').attr('disabled', 'disabled');
            $('#txtLetterDate').attr('disabled', 'disabled');
            $('#txtDevolutionDate').attr('disabled', 'disabled');
            if ($('#hfAksi').val() == 'update') {
                $('#ddlPengurusan').attr('disabled', 'disabled');
            }

            //format tanggal
            $('#txtTglSuratPengurusan').datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                minDate: 0
            });

            $('#txtTglSuratPengurusan').inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });


            $('#btnCancel').click(function () {
                parent.$('#dialog1').dialog('close');

                return false;
            });


            $('#btnSubmit').click(function (e) {
                if (!validator.validate())
                    return;

                e.preventDefault();

                var id = $('#hfDevolutionProcessDetailId').val();
                //mengupload file
                if (id > 0) {
                    if ($('#hfAksi').val() == 'insert') {
                        //alert('insert1 ' + $('#hfLastDevalutionAction').val());
                        if ($('#hfLastDevalutionAction').val() == null) {
                            //alert('update1 ' + $('#hfLastDevalutionAction').val());
                            aksiSimpan('updatedevalutionprocess');
                        } else {
                            //alert('insert2 ' + $('#hfLastDevalutionAction').val());
                            aksiSimpan('insertdevalutionprocess');
                        }
                    } else {
                        //alert('update2 ' + $('#hfLastDevalutionAction').val());
                        aksiSimpan('updatedevalutionprocess');
                    }
                } else {
                    alert('error DevalutionProcessID tidak ada!');
                }
            });

            // function untuk simpan dan ubah
            function aksiSimpan(aksi) {
                if (uploader.files.length > 0) // Insert with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'hfDevolutionProcessDetailId': encodeURIComponent($('#hfDevolutionProcessDetailId').val()),
                        'hfDevolutionProcessId': encodeURIComponent($('#hfDevolutionProcessId').val()),
                        'ddlPengurusan': encodeURIComponent($('#ddlPengurusan').val()),
                        'hfDevolutionId': encodeURIComponent($('#hfDevolutionId').val()),
                        'txtNoSuratPengurusan': encodeURIComponent($('#txtNoSuratPengurusan').val()),
                        'txtTglSuratPengurusan': encodeURIComponent($('#txtTglSuratPengurusan').val())
                    };

                    uploader.settings.url = '<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=' + aksi;
                    uploader.start();
                } else {
                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=' + aksi,
                                $("#form1")
                                .find("input,textarea,select,hidden")
                                .not("#__VIEWSTATE,#__EVENTVALIDATION")
                                .serialize())
                            .done(function (data) {
                                var r = JSON.parse(data);

                            })
                            .fail(function () {
                                alert('Data gagal di ' + aksi);
                            });
                }

                parent.$('#dialog1').dialog('close');
                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

                return false;
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<table>
            <tr>
                <td>Nama Debitur</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDebtorName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>ID Debitur</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDebtorId" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Nomor Surat Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtLetterNo" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Tgl. Surat Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtLetterDate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                <br />
                </td>
            </tr>
            <tr>
                <td>Tgl. Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDevolutionDate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Tahap Proses Pengurusan</td>
                <td>:</td>
                <td>
                    <asp:DropDownList ID="ddlPengurusan" runat="server">
                    </asp:DropDownList>&nbsp;<span
                    style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td>Nomor Surat Pengurusan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtNoSuratPengurusan" runat="server"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td>Tgl. Surat Pengurusan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtTglSuratPengurusan" runat="server"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td>Lampiran</td>
                <td>:</td>
                <td>
                    <div id="container">
                    <a id="pickfiles" class="plupload_button plupload_add ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                        href="#"><span class="ui-button-icon-primary ui-icon ui-icon-circle-plus" /><span
                            class="ui-button-text">Add Files</span> </a>
                    <br />
                    <div id="filelist"></div>
                </div>
                </td>
            </tr>
            <tr align="right">
                <td colspan="3">
                <br />
                
                    <button id="btnSubmit" type="submit" runat="server">
                        Simpan</button>
                    <button id="btnCancel" type="button">
                        Batal</button>
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:HiddenField ID="hfDevolutionProcessDetailId" runat="server" />
                    <asp:HiddenField ID="hfDevolutionProcessId" runat="server" />
                    <asp:HiddenField ID="hfLastDevalutionAction" runat="server" />
                    <asp:HiddenField ID="hfAksi" runat="server" />
                    <asp:HiddenField ID="hfDevolutionId" runat="server" />
                </td>
            </tr>
          </table>    
    </div>
    </form>
</body>
</html>
